# !/bin/bash
# install ice and xce from the server
echo "--------------------------------------------------"
echo "this script copy the ice and xce from the"
echo "10.22.241.101, then extract ice to /opt/ and "
echo "xce to /usr/local, finally invoke ldconfig update"
echo "the shared lib path"
echo "--------------------------------------------------"

ice=Ice-3.3.1-binary-release-rhel5.tar.bz2
xce=usr_local_xce-binary-rhel5.tar.bz2
ice_path=/opt/
xce_path=/usr/local/

# get the packets
if ! ([ -f $ice ] && [ $(wc -c "$ice" | cut -d ' ' -f 1) -ge 12467961 ]); then
    if ! scp root@10.22.241.101:/root/$ice . ; then
        echo "copy the $ice error!"
        exit 1
    fi
fi

if ! ([ -f $xce ] && [ $(wc -c "$xce" | cut -d ' ' -f 1) -ge 22396270 ]); then
    if ! scp root@10.22.241.101:/root/$xce . ; then
        echo "copy the $xce error!"
        exit 1
    fi
fi

echo copy the packet...

# copy and unpacket
if ! mv -f "$ice" "$ice_path"; then
    echo copy the ice to "$ice_path" error! 
    exit 1
fi

if ! mv -f "$xce" "$xce_path"; then
    echo copy the xce to "$xce_path" error! 
    exit 1
fi

ice_tar=$ice_path$ice
xce_tar=$xce_path$xce

echo extract the packet...

for pack in $ice_tar $xce_tar
do
    dir=`dirname $pack`
    if ! tar xjf $pack -C $dir; then
        echo extract $pack error!
        exit 1
    fi
done

echo ldconfig...
# add the path to ldconfig
if [ -d "/etc/ld.so.conf.d" ] ;then
    cat > /etc/ld.so.conf.d/ice.conf << EOF
/opt/Ice-3.3/lib/
/usr/local/xce/lib/
/opt/Ice-3.3/lib64/
/usr/local/xce/lib64/
EOF

    if [ -d "/etc/ld.so.conf.d" ] && ldconfig ; then
        echo "ldconfig successly"
    else
        echo "ldconfig error!"
        exit 1
    fi
else
    echo the /etc/ld.so.conf.d not exist!
    exit 1
fi

echo "ice install successly!"
